package bridge;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.Vector;

class Main 
{
	public static void main(String [] args)
	{
		new Bridge().start();
	}
}

class Bridge 
{
	public void start()
	{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		try
		{
			// Read the number of cases.
			int numOfCases = Integer.parseInt(reader.readLine());
			
			for (int count = 0; count < numOfCases; count++)
			{
				// Read blank line.
				reader.readLine();
				
				// Read the number of people 'n'.
				int numOfPeople = Integer.parseInt(reader.readLine());
				
				// Create a stack to do hold people's speed.
				Stack<Integer> bridgeSide1 = new Stack<Integer>();
				
				// Read the speeds.
				for (int counter = 0; counter < numOfPeople; counter++)
				{
					int speed = Integer.parseInt(reader.readLine());
					
					// Save it.
					bridgeSide1.push(speed);
				}
				
				// Calculate total time.
				bridgeTime(bridgeSide1);
			}
		} 
		catch (IOException ex) 
		{
			ex.printStackTrace();
		}
	}
	
	void bridgeTime(Stack<Integer> bridgeSide1)
	{
		Stack<Integer> tempBridgeOne = new Stack<Integer>();
		Stack<Integer> tempBridgeTwo = new Stack<Integer>();
		Iterator<Integer> bridgeIter = bridgeSide1.iterator();
		
		while(bridgeIter.hasNext())
		{
			Integer element = bridgeIter.next();
			
			tempBridgeOne.add(element);
			tempBridgeTwo.add(element);
		}
		
		
		HashMap<Integer, String> optionOne = optionOne(tempBridgeOne);
		HashMap<Integer, String> optionTwo = optionTwo(tempBridgeTwo);
		
		Set set = optionOne.entrySet();
		Set set2 = optionTwo.entrySet();
		
		Iterator iter = set.iterator();
		Iterator iter2 = set2.iterator();
		
		Integer optionOneTime = -1;
		Integer optionTwoTime = -1;
		
		String tracker = "";
		String trackerTwo = "";
		
		while (iter.hasNext())
		{
			Map.Entry me = (Map.Entry) iter.next();
			
			optionOneTime = (Integer)me.getKey();
			tracker = (String)me.getValue();
		}
		
		while (iter2.hasNext())
		{
			Map.Entry me = (Map.Entry) iter2.next();
			
			optionTwoTime = (Integer)me.getKey();
			trackerTwo = (String)me.getValue();
		}
		
		if (optionOneTime <= optionTwoTime)
		{
			printResults(optionOneTime, tracker);
		} 
		else 
		{
			printResults(optionTwoTime, trackerTwo);
		}
	}
	
	void printResults(int time, String tracker)
	{
		System.out.println(time);
		System.out.println(tracker);
	}
	
	/*
	 * Take the two fastest, then return the fastest, then take the two slowest, then the next fastest.
	 */
	HashMap<Integer, String> optionOne(Stack<Integer> bridgeSide1)
	{
				// The other side of the bridge as an array (the side people want to be at).
				Stack<Integer> happyBridge = new Stack<Integer>();
				
				// A variable counter to determine how many people crossed.
				int peopleCrossed = 0;
				
				// A variable counter to determine the total time need to cross bridge.
				int totalTime = 0;
				
				// A String value to track people crossing the bridge.
				String tracker = "";
				
				while(!bridgeSide1.isEmpty())
				{
					// Sort the elements.
					Collections.sort(bridgeSide1);
					
					if (bridgeSide1.size() >= 2)
					{
						// Retrieve the first two people (the two with highest Speeds).
						int person1 = bridgeSide1.firstElement();
						bridgeSide1.remove(0);
						int person2 = bridgeSide1.firstElement();
						bridgeSide1.remove(0);
						
						// Cross to the other side and calculate speed of the slower of the two.
						happyBridge.push(person1);
						happyBridge.push(person2);
						
						// Add to tracker.
						tracker += "" + person1 + " " + person2 + "\r";
						
						if (person1 > person2)
							totalTime += person1;
						else
							totalTime += person2;
						
						
						if (!bridgeSide1.isEmpty())
						{
							// Sort happyBridge.
							Collections.sort(happyBridge);
							
							// Now take the fastest person in happyBridge and return it to the other side.
							int fastPerson = happyBridge.firstElement();
							happyBridge.remove(0);
							
							tracker += "" + fastPerson + "\r";
							
							bridgeSide1.push(fastPerson);
							
							totalTime += fastPerson;
							
							Collections.sort(bridgeSide1);
							
							// Take the slowest two in bridgeSide1 and move them to the other side.
							// 
							int slowPerson1 = bridgeSide1.pop();
							int slowPerson2 = bridgeSide1.pop();
							
							happyBridge.push(slowPerson1);
							happyBridge.push(slowPerson2);
							
							if (slowPerson1 > slowPerson2)
								totalTime += slowPerson1;
							else
								totalTime += slowPerson2;
							
							tracker += "" + slowPerson1 + " " + slowPerson2 + "\r";
						}
						
						if (!bridgeSide1.isEmpty())
						{
							Collections.sort(happyBridge);
							
							// Take the highest crossing speed on bridgeSide2 and move to side 1.
							int secondFastPerson = happyBridge.firstElement();
							happyBridge.remove(0);
							
							bridgeSide1.push(secondFastPerson);
							
							totalTime += secondFastPerson;
							
							tracker += "" + secondFastPerson + "\r";
						}
					} 
					else
					{
						// Retrieve the person.
						int person1 = bridgeSide1.pop();
						
						// Cross him to other side.
						happyBridge.push(person1);
						
						tracker += "" + person1 + "\r";
						
						totalTime += person1;
					}
				}
				
				HashMap<Integer, String> map = new HashMap<Integer, String>();
				
				map.put(totalTime, tracker);
				
				return map;
			}
	
	/*
	 * 1 99 ____ 98 100, 99 ___ 1 98 100, 98 99 ___ 1 100,  99 + 1 + 98 + 1 + 100 = 299
	 * 1 99 _____ 98 100, 99 ___ 1 98 100, 98 99 100 _ 1, 99 100 ___ 98 1, 99 + 1 + 100 + 98 + 98 = 396
	 */
	HashMap<Integer, String> optionTwo(Stack<Integer> bridgeSide1)
	{
		// The other side of the bridge as an array (the side people want to be at).
		Stack<Integer> happyBridge = new Stack<Integer>();
		
		// A variable counter to determine how many people crossed.
		int peopleCrossed = 0;
		
		// A variable counter to determine the total time need to cross bridge.
		int totalTime = 0;
		
		// A String value to track people crossing the bridge.
		String tracker = "";
		
		while(!bridgeSide1.isEmpty())
		{
			// Sort the elements.
			Collections.sort(bridgeSide1);
			
			if (bridgeSide1.size() >= 2)
			{
				// Retrieve the first two people (the two with highest Speeds).
				int person1 = bridgeSide1.firstElement();
				bridgeSide1.remove(0);
				int person2 = bridgeSide1.firstElement();
				bridgeSide1.remove(0);
				
				// Cross to the other side and calculate speed of the slower of the two.
				happyBridge.push(person1);
				happyBridge.push(person2);

				// Add to tracker.
				tracker += "" + person1 + " " + person2 + "\r";
				
				if (person1 > person2)
					totalTime += person1;
				else
					totalTime += person2;
				
				
				if (!bridgeSide1.isEmpty())
				{
					// Sort happyBridge.
					Collections.sort(happyBridge);
					
					// Now take the fastest person in happyBridge and return it to the other side.
					int fastPerson = happyBridge.firstElement();
					happyBridge.remove(0);
					
					tracker += "" + fastPerson + "\r";
					
					bridgeSide1.push(fastPerson);
					
					totalTime += fastPerson;
					
					Collections.sort(bridgeSide1);
					
					// Take the front two in bridgeSide1 and move them to the other side*.
					int frontPerson1 = bridgeSide1.firstElement();
						bridgeSide1.remove(0);
					int frontPerson2 = bridgeSide1.firstElement();
						bridgeSide1.remove(0);
					
					happyBridge.push(frontPerson1);
					happyBridge.push(frontPerson2);
					
					if (frontPerson1 > frontPerson2)
						totalTime += frontPerson1;
					else
						totalTime += frontPerson2;
					
					tracker += "" + frontPerson1 + " " + frontPerson2 + "\r";
				}
				
				if (!bridgeSide1.isEmpty())
				{
					Collections.sort(happyBridge);
					
					// Take the highest crossing speed on bridgeSide2 and move to side 1.
					int secondFastPerson = happyBridge.firstElement();
					happyBridge.remove(0);
					
					bridgeSide1.push(secondFastPerson);
					
					totalTime += secondFastPerson;
					
					tracker += "" + secondFastPerson + "\r";
				}
			} 
			else
			{
				// Retrieve the person.
				int person1 = bridgeSide1.pop();
				
				// Cross him to other side.
				happyBridge.push(person1);
				
				tracker += "" + person1 + "\r";
				
				totalTime += person1;
			}
		}
		
		HashMap<Integer, String> map = new HashMap<Integer, String>();
		
		map.put(totalTime, tracker);
		
		return map;
	}
}